package ntu.metaweb;

import ntu.metaweb.result.Comment;
import ntu.metaweb.result.Comments;
import ntu.metaweb.result.ContactList;
import ntu.metaweb.result.ContactListConverter;
import ntu.metaweb.result.Link;
import ntu.metaweb.result.LinkComment;
import ntu.metaweb.result.LinkComments;
import ntu.metaweb.result.NumberedPageRating;
import ntu.metaweb.result.Page;
import ntu.metaweb.result.PageLinks;
import ntu.metaweb.result.PageRating;
import ntu.metaweb.result.PageTags;
import ntu.metaweb.result.PagesWithTag;
import ntu.metaweb.result.Tag;
import ntu.metaweb.result.Title;

import com.thoughtworks.xstream.XStream;

public class XMLMarshaller {
	private static XMLMarshaller instance = new XMLMarshaller();;
	
	public static XMLMarshaller getInstance() {
		System.out.println("test test");
		return XMLMarshaller.instance;
	}
	
	private XStream xstream;
	
	private XMLMarshaller() {
		this.xstream = new XStream();
		xstream.processAnnotations(Comments.class);
		xstream.processAnnotations(Comment.class);
		xstream.processAnnotations(Link.class);
		xstream.processAnnotations(PageRating.class);
		xstream.processAnnotations(NumberedPageRating.class);
		xstream.processAnnotations(Tag.class);
		xstream.processAnnotations(Title.class);
		xstream.processAnnotations(PageLinks.class);
		xstream.processAnnotations(PageTags.class);
		xstream.processAnnotations(Page.class);
		xstream.processAnnotations(PagesWithTag.class);
		xstream.processAnnotations(LinkComment.class);
		xstream.processAnnotations(LinkComments.class);
		xstream.processAnnotations(ContactList.class);
		xstream.registerConverter(new ContactListConverter());
		xstream.setMode(XStream.NO_REFERENCES);
	}
	
	public String marshall(Object o) {
		return xstream.toXML(o);
	}
	
	public Object unmarshall(String xml) {
		return xstream.fromXML(xml);
	}
}
